#!/bin/bash

# $1: source directory or file
# $2: pool id
# $3: upgrade level
# $4: cache size
# $5: external cache size
# $6: CDC ratio
# $7: working id

if [ $# -ne 7 ]; then
    echo "Error: Missing argument"
    exit 1
fi

set -e

SRC_DIR=$1
POOL_ID=$2
WD_ID=$7

TEST_DIR=/data/cbj/destor
WORKING_BKP=${TEST_DIR}/working${WD_ID}_bak
WORKING_DIR=${TEST_DIR}/working${WD_ID}${POOL_ID}
LOG_DIR=${TEST_DIR}/log

CONFIG=-p"working-directory $WORKING_DIR"
CONFIG+=", fake-containers 1"
CONFIG+=", fingerprint-index-cache-size $4"
CONFIG+=", fingerprint-external-cache-size $5"
CONFIG+=", recipe-cdc-ratio $6"

cd /home/cbj/destor-test
# remake
set -x

# update test
redis-cli -p 6666 FLUSHALL
redis-cli -p 6667 FLUSHALL
rm -f ${WORKING_DIR}/container.pool_new
rm -f ${WORKING_DIR}/recipes/bv1*
cp ${WORKING_BKP}/destor.stat ${WORKING_DIR}
cp ${WORKING_BKP}/backupversion.count ${WORKING_DIR}/recipes

./destor-cbj-test-special -u0 ${SRC_DIR} -i"$3" "${CONFIG}" > ${LOG_DIR}/pool_${POOL_ID}.log
rm ${WORKING_DIR}/container.pool_new
rm -r ${WORKING_DIR}/recipes/bv1*
